// API base URL configuration
import websiteConfig from '../../website.json';

export const AG_ID = String(websiteConfig.AG_ID);
export const AG_NAME = String(websiteConfig.AG_NAME);
export const WEIXIN_ID = String(websiteConfig.WEIXIN_ID);
export const QQ_GROUP = String(websiteConfig.QQ_GROUP);
export const QQ_GROUP_QRCODE = String(websiteConfig.QQ_GROUP_QRCODE);

export const QQ_ID = String(websiteConfig.QQ_ID);
export const WEIXIN_QRCODE = String(websiteConfig.WEIXIN_QRCODE);
export const ALIPAY_QRCODE = String(websiteConfig.ALIPAY_QRCODE);

export const WEBSITE_TITLE = String(websiteConfig.WEBSITE_TITLE);
export const WEBSITE_ICON = String(websiteConfig.WEBSITE_ICON);
export const WEBSITE_NAME = String(websiteConfig.WEBSITE_NAME);
export const BEIAN_ID = String(websiteConfig.BEIAN_ID);
export const WEBSITE_EMAIL = String(websiteConfig.WEBSITE_EMAIL);
export const WEBSITE_ICP = String(websiteConfig.BEIAN_ID);
export const WEBSITE_DESCRIPTION = String(websiteConfig.WEBSITE_DESCRIPTION);
export const WEBSITE_KEYWORDS = String(websiteConfig.WEBSITE_keywords);

export const WEBSITE_URL = String(websiteConfig.WEBSITE_URL);

export const OSS_BASE_URL = String(websiteConfig.OSS_BASE_URL);
export const CDN_BASE_URL = String(websiteConfig.CDN_BASE_URL);


// 动态获取API基础URL，支持HTTP和HTTPS协议自适应
function getApiBaseUrl(): string {
  const isDevelopment = process.env.NODE_ENV === 'development';
  const baseUrl = isDevelopment 
    ? String(websiteConfig.LOCAL_API_BASE_URL)
    : String(websiteConfig.API_BASE_URL);
  
  // 如果当前页面是HTTPS，则将API URL也改为HTTPS
  if (typeof window !== 'undefined' && window.location.protocol === 'https:') {
    return baseUrl.replace(/^http:/, 'https:');
  }
  
  return baseUrl;
}

export const API_BASE_URL = getApiBaseUrl();

// 保留本地API地址以备特殊需求
export const LOCAL_API_BASE_URL = String(websiteConfig.LOCAL_API_BASE_URL);


// API endpoints
export const API_ENDPOINTS = {
  USER_EDIT_INFO: `${API_BASE_URL}/v1/user/editUserInfo`,
  LOGIN: `${API_BASE_URL}/v1/user/login`,
  LOGIN_OUT: `${API_BASE_URL}/v1/user/loginOut`,
  SMS_LOGIN: `${API_BASE_URL}/v1/user/smsLogin`,
  USER_BLOCK: `${API_BASE_URL}/v1/user/block`,
  USER_BLOCK_ALL: `${API_BASE_URL}/v1/user/blockAll`,
  SEND_SMS_CODE: `${API_BASE_URL}/v1/user/sendSmsCode`,
  USER_FIND_PASSWORD: `${API_BASE_URL}/v1/user/smsFindPassword`,
  REGISTER: `${API_BASE_URL}/v1/user/reg`, // 添加注册链接
  GET_VERIFY: `${API_BASE_URL}/v1/user/getVerify`,
  RESEND_EMAIL: `${API_BASE_URL}/v1/user/resendEmail`, // 添加重发邮件链接
  ACTIVATE_EMAIL: `${API_BASE_URL}/v1/user/activityEmail`, // 添加激活邮箱链接
  ACCOUNT_SETUP: `${API_BASE_URL}/v1/user/accountSetup`, // 添加账户设置链接、
  USER_ME: `${API_BASE_URL}/v1/user/me`, //
  USER_LIST: `${API_BASE_URL}/v1/user/allUserList`, //
  USER_MY_AGENT: `${API_BASE_URL}/v1/user/myAgent`, //

  OSS_STS: `${API_BASE_URL}/v1/oss/sts`, //  

  GET_POST_OSS_UPLOAD: `${API_BASE_URL}/v1/oss/get_post_signature_for_oss_upload`, // 
  UPLOAD_FILE_INFO: `${API_BASE_URL}/v1/media/upload_file_info`, //  

  POST_NEW_POST: `${API_BASE_URL}/v1/posts/newPost`, //
  POST_EDIT_POST: `${API_BASE_URL}/v1/posts/editPost`, //
  POST_DELETE: `${API_BASE_URL}/v1/posts/delPost`, //
  POST_LIST: `${API_BASE_URL}/v1/posts/list`, //
  POST_TIMELINE: `${API_BASE_URL}/v1/posts/timeline`, //

  GROUP_PLANS_LIST: `${API_BASE_URL}/v1/groups/list`, //  

  REDEEMCODE_LIST: `${API_BASE_URL}/v1/redeemcode/list`, //
  REDEEMCODE_USER_LIST: `${API_BASE_URL}/v1/redeemcode/userList`, //

  REDEEMCODE_REQ_LIST: `${API_BASE_URL}/v1/redeemcode/reqList`, //
  REDEEMCODE_GET: `${API_BASE_URL}/v1/redeemcode/get`, //
  REDEEMCODE_USE: `${API_BASE_URL}/v1/redeemcode/use`, //
  REDEEMCODE_NEW_QUE: `${API_BASE_URL}/v1/redeemcode/newRedeemCodeReq`, //
  REDEEMCODE_CANCLE: `${API_BASE_URL}/v1/redeemcode/cancle`, //
  REDEEMCODE_NEW: `${API_BASE_URL}/v1/redeemcode/newRedeemCode`, //

  
  UPLSUBSCRIPTON_PLANS_LIST: `${API_BASE_URL}/v1/groups/list`, //  
  UPLSUBSCRIPTON_PLANS_SAVE: `${API_BASE_URL}/v1/groups/newGroup`, //
  UPLSUBSCRIPTON_PLANS_UPDATE: `${API_BASE_URL}/v1/groups/updateGroup`, //
  UPLSUBSCRIPTON_PLANS_TOP:  `${API_BASE_URL}/v1/groups/topGroup`,
  UPLSUBSCRIPTON_PLANS_DELETE: `${API_BASE_URL}/v1/groups/removeGroup`,  

  UPLSUBSCRIPTON_MYPLAN: `${API_BASE_URL}/v1/transactions/myPlan`, //  

  UPLSUBSCRIPTON_ALLPLAN: `${API_BASE_URL}/v1/transactions/list`, //  

  UPLSUBSCRIPTON_PLANS_SUBS: `${API_BASE_URL}/v1/transactions/save`,   
  UPLSUBSCRIPTON_PLANS_UNSUBS: `${API_BASE_URL}/v1/transactions/unSubscribe`,   
  UPLSUBSCRIPTON_PLANS_SUBFree : `${API_BASE_URL}/v1/transactions/saveFree`,

  ORDER_LIST: `${API_BASE_URL}/v1/transactions/orderList`,
  ORDER_SAVE: `${API_BASE_URL}/v1/transactions/saveOrder`,

  NOTIFICATION_LIST: `${API_BASE_URL}/v1/notifications/list`,
  NOTIFICATION_READ: `${API_BASE_URL}/v1/notifications/read`,
  NOTIFICATION_DELETE: `${API_BASE_URL}/v1/notifications/delete`,
  NOTIFICATION_NEW: `${API_BASE_URL}/v1/notifications/new`,
  NOTIFICATION_COUNT: `${API_BASE_URL}/v1/notifications/count`,

} as const;